package com.zeratul.common.pool.config.thread;

import com.zeratul.common.core.constant.PoolConstants;
import com.zeratul.common.pool.utils.ThreadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

import java.util.concurrent.Executor;

@Slf4j
@Configuration
public class DelayThreadPoolConfig {

    /**
     * 线程池大小
     */
    private final int poolSize = 100;

    /**
     * 延迟队列处理线程池
     * 设置为懒加载，需要时再创建延迟队列线程池
     */
    @Lazy
    @Bean(name = PoolConstants.DELAY_POOL)
    protected Executor delayExecutorService() {
        //创建线程池
        return ThreadUtils.newThreadPool(1,
                1,
                60, poolSize,
                "delay-pool",
                true);
    }
}
